﻿/*
 * @file: DataAccessHelper.cs
 * @in namespace: DAL
 */
using System;
using System.Configuration;

namespace DAL
{
    public class DataAccessHelper
    {
        /// <summary>
        /// Get data access type from web.config
        /// </summary>
        public static string DataAccessStringType = ConfigurationManager.AppSettings["DataAccessLayerType"];

        #region Methods
        /// <summary>
        /// return an instance of IBouquet
        /// </summary>
        /// <returns>instance of IBouquet</returns>
        public static IBouquet GetBouquetDA()
        {
            IBouquet result = null;
            if (String.IsNullOrEmpty(DataAccessStringType))
                throw new NullReferenceException("DataAccessType in web.config is null of empty");
            else
            {
                if (DataAccessStringType.Equals("SQLSERVER"))
                {
                    Type type = Type.GetType("DAL.BouquetDA");
                    result = (BouquetDA)Activator.CreateInstance(type);
                }
            }
            return result;
        }

        /// <summary>
        /// return an instance of IDiscount
        /// </summary>
        /// <returns>instance of IDiscount</returns>
        public static IDiscount GetDiscountDA()
        {
            IDiscount result = null;
            if (String.IsNullOrEmpty(DataAccessStringType))
                throw new NullReferenceException("DataAccessType in web.config is null of empty");
            else
            {
                if (DataAccessStringType.Equals("SQLSERVER"))
                {
                    Type type = Type.GetType("DAL.DiscountDA");
                    result = (DiscountDA)Activator.CreateInstance(type);
                }
            }
            return result;
        }

        /// <summary>
        /// return an instance of IRoles
        /// </summary>
        /// <returns>instance of IRoles</returns>
        public static IRoles GetRolesDA()
        {
            IRoles result = null;
            if (String.IsNullOrEmpty(DataAccessStringType))
                throw new NullReferenceException("DataAccessType in web.config is null of empty");
            else
            {
                if (DataAccessStringType.Equals("SQLSERVER"))
                {
                    Type type = Type.GetType("DAL.RolesDA");
                    result = (RolesDA)Activator.CreateInstance(type);
                }
            }
            return result;
        }

        /// <summary>
        /// return an instance of IUsers
        /// </summary>
        /// <returns>instance of IUsers</returns>
        public static IUsers GetUsersDA()
        {
            IUsers result = null;
            if (String.IsNullOrEmpty(DataAccessStringType))
                throw new NullReferenceException("DataAccessType in web.config is null of empty");
            else
            {
                if (DataAccessStringType.Equals("SQLSERVER"))
                {
                    Type type = Type.GetType("DAL.UsersDA");
                    result = (UsersDA)Activator.CreateInstance(type);
                }
            }
            return result;
        }

        public static IOrderDetails GetOrderDetailsDA()
        {
            IOrderDetails result = null;
            if (String.IsNullOrEmpty(DataAccessStringType))
                throw new NullReferenceException("DataAccessType in web.config is null of empty");
            else
            {
                if (DataAccessStringType.Equals("SQLSERVER"))
                {
                    Type type = Type.GetType("DAL.OrderDetailsDA");
                    result = (OrderDetailsDA)Activator.CreateInstance(type);
                }
            }
            return result;
        }

        /// <summary>
        /// return an instance of IMessage
        /// </summary>
        /// <returns>instance of IMessage</returns>
        public static IMessage GetMessageDA()
        {
            IMessage result = null;
            if (String.IsNullOrEmpty(DataAccessStringType))
                throw new NullReferenceException("DataAccessType in web.config is null of empty");
            else
            {
                if (DataAccessStringType.Equals("SQLSERVER"))
                {
                    Type type = Type.GetType("DAL.MessageDA");
                    result = (MessageDA)Activator.CreateInstance(type);
                }
            }
            return result;
        }

        /// <summary>
        /// return an instance of INews
        /// </summary>
        /// <returns>instance of INews</returns>
        public static INews GetNewsDA()
        {
            INews result = null;
            if (String.IsNullOrEmpty(DataAccessStringType))
                throw new NullReferenceException("DataAccessType in web.config is null of empty");
            else
            {
                if (DataAccessStringType.Equals("SQLSERVER"))
                {
                    Type type = Type.GetType("DAL.NewsDA");
                    result = (NewsDA)Activator.CreateInstance(type);
                }
            }
            return result;
        }

        /// <summary>
        /// return an instance of IOccasion
        /// </summary>
        /// <returns>instance of IOccasion</returns>
        public static IOccasion GetOccasionDA()
        {
            IOccasion result = null;
            if (String.IsNullOrEmpty(DataAccessStringType))
                throw new NullReferenceException("DataAccessType in web.config is null of empty");
            else
            {
                if (DataAccessStringType.Equals("SQLSERVER"))
                {
                    Type type = Type.GetType("DAL.OccasionDA");
                    result = (OccasionDA)Activator.CreateInstance(type);
                }
            }
            return result;
        }

        /// <summary>
        /// return an instance of IOrders
        /// </summary>
        /// <returns>instance of IOrders</returns>
        public static IOrders GetOrdersDA()
        {
            IOrders result = null;
            if (String.IsNullOrEmpty(DataAccessStringType))
                throw new NullReferenceException("DataAccessType in web.config is null of empty");
            else
            {
                if (DataAccessStringType.Equals("SQLSERVER"))
                {
                    Type type = Type.GetType("DAL.OrdersDA");
                    result = (OrdersDA)Activator.CreateInstance(type);
                }
            }
            return result;
        }

        /// <summary>
        /// return an instance of IBilling
        /// </summary>
        /// <returns>instance of IBilling</returns>
        public static IBilling GetBillingDA()
        {
            IBilling result = null;
            if (String.IsNullOrEmpty(DataAccessStringType))
                throw new NullReferenceException("DataAccessType in web.config is null of empty");
            else
            {
                if (DataAccessStringType.Equals("SQLSERVER"))
                {
                    Type type = Type.GetType("DAL.BillingDA");
                    result = (BillingDA)Activator.CreateInstance(type);
                }
            }
            return result;
        }

        /// <summary>
        /// return an instance of IShippingDetails
        /// </summary>
        /// <returns>instance of IShippingDetails</returns>
        public static IShippingDetails GetShippingDetailsDA()
        {
            IShippingDetails result = null;
            if (String.IsNullOrEmpty(DataAccessStringType))
                throw new NullReferenceException("DataAccessType in web.config is null of empty");
            else
            {
                if (DataAccessStringType.Equals("SQLSERVER"))
                {
                    Type type = Type.GetType("DAL.ShippingDetailsDA");
                    result = (ShippingDetailsDA)Activator.CreateInstance(type);
                }
            }
            return result;
        }
        #endregion

        private DataAccessHelper()
        {
            //
            // TODO: Add constructor logic here
            //
        }
    }
}